﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using LGE;

namespace LGE
{
    public class SpriteSheetState
    {
        List<Texture2D> sprites;
        public List<SpriteSheet> spriteSheets;
        EngineObject obj;
        public int actualState = 0;
        public bool completed = false;

        public SpriteSheetState(EngineObject gameObject)
        {
            this.obj = gameObject;
            sprites = new List<Texture2D>();
            spriteSheets = new List<SpriteSheet>();
        }

        public void Update(GameTime gameTime)
        {
            spriteSheets[actualState].Update(gameTime);
            completed = spriteSheets[actualState].completed;
        }

        public void Add(Texture2D sprite, SpriteSheet ss)
        {
            sprites.Add(sprite);
            spriteSheets.Add(ss);
        }

        public void Change(int newState)
        {
            if (newState == actualState) return;
            spriteSheets[actualState].actualHeight = 0;
            spriteSheets[actualState].actualWidth = 0;
            spriteSheets[actualState].completed = false;
            actualState = newState;
            obj.sprite = sprites[newState];
            completed = false;
            obj.origin.X = spriteSheets[newState].frameWidth / 2;
            obj.origin.Y = spriteSheets[newState].frameHeight / 2;
            obj.sourceRectangle.Width = spriteSheets[newState].frameWidth;
            obj.sourceRectangle.Height = spriteSheets[newState].frameHeight;
        }

        public void ChangeToNext()
        {
            if (actualState + 1 >= sprites.Count)
                Change(0);
            else
                Change(actualState + 1);
        }

    }
}
